package com.cmy.framework_utils

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle

/**
 * @name:
 *  JumpPageUtile
 * @package:
 *  com.cmy.framework_utils
 * @date:
 *  2023/5/611:29
 * @author
 *    cmy
 * @description
 *  页面跳转封装
 */
object JumpPageUtils {

    /**
     * 页面跳转，实现跳转函数处理
     * @param context
     *         环境参数变化
     */
     inline fun <reified  T : Activity> startActivity(context:Context,block: Intent.() -> Unit){
        val  intent = Intent(context,T::class.java)
        block.invoke(intent)
        context.startActivity(intent)
    }


    /**
     * 页面跳转，实现跳转函数处理
     *
     */
    inline fun <reified  T : Activity> startActivityBundle(context:Context,block: Bundle.() -> Unit){
        val  intent = Intent(context,T::class.java)
        val bundle = Bundle()
        block.invoke(bundle)
        intent.putExtras(bundle)
        context.startActivity(intent)
    }


    /**
     * 跳转添加转场动画效果
     */
    inline fun  <reified  T : Activity> startActivity(activity: Activity, block: Intent.() -> Unit, enterAnim:Int, exitAnim:Int){
        val  intent = Intent(activity,T::class.java)
        block.invoke(intent)
        activity.startActivity(intent)
        //转场动画效果
        activity.overridePendingTransition(enterAnim,exitAnim)
    }



    /**
     * 页面跳转，实现跳转函数处理,添加转场动画效果
     *
     */
    inline fun <reified  T : Activity> startActivityBundle(activity:Activity,block: Bundle.() -> Unit,enterAnim:Int, exitAnim:Int){
        val  intent = Intent(activity,T::class.java)
        val bundle = Bundle()
        block.invoke(bundle)
        intent.putExtras(bundle)
        activity.startActivity(intent)
        //转场动画效果
        activity.overridePendingTransition(enterAnim,exitAnim)
    }
}